package routers

import (
	. "blogApi/controllers"
	"blogApi/controllers/api"
	"github.com/astaxie/beego"
)

func init() {
	// 前端路由
	beego.Router("/", &MainController{})
	home := beego.NewNamespace("/home",
		beego.NSRouter("/article_list", &HomeController{}, "get:ArticleList"),
		beego.NSRouter("/article/:id([0-9]+)", &HomeController{}, "get:Article"),
		beego.NSRouter("/article_top", &HomeController{}, "get:ArticleTop"),
		beego.NSRouter("/home/category", &HomeController{}, "get:Category"),
	)
	beego.AddNamespace(home)

	// 后台需要验证的路由
	ns := beego.NewNamespace("/api",
		beego.NSNamespace("/test",
			beego.NSRouter("/get", &api.TestController{}, "get:Get"),
			beego.NSRouter("/index", &api.TestController{}, "get:Index"),
			beego.NSRouter("/info/:id([0-9]+", &api.TestController{}, "get:Info"),
		),
		beego.NSNamespace("/admin",
			beego.NSRouter("/login", &api.AdminController{}, "post:Login"),
			beego.NSRouter("/logout", &api.AdminController{}, "post:logout"),

		),
	)
	beego.AddNamespace(ns)
}
